home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks95
/
IsNative.sit
/
Is Native
/
AboutAnimation.c
< prev
next >
Wrap
Text File
|
1995-06-24
|
4KB
|
212 lines
//
// File: AboutAnimation.c
// Project: IsNative.π
// Author: Glenn L. Austin
// Symantec Corporation
//
#include <QDOffscreen.h>
#include <Traps.h>
#include "IsNative.h"
typedef pascal Boolean (*GNEPP)(short, EventRecord*);
extern WindowPtr aboutWindow;
static Str255 aboutStr = "\p%PNormal=68K, %IItalic%I=PPC, %B%CBold%P=fat •• Is Native? ©1995, Glenn L. Austin, All rights reserved worldwide. ";
Rect aboutR = {42, 0, 54, 377};
Rect srcR, targR;
GWorldPtr aboutGW = nil;
static GNEPP oldGetNextEvent;
static unsigned long lastTick;
static pascal Boolean MyGetNextEvent(short mask, EventRecord* evt)
{
long oldA4 = SetA4World();
Rect r;
unsigned long ticksBetweenUpdate = 4;
Boolean retVal = (*oldGetNextEvent)(mask, evt);
short adder = -1;
GrafPtr oldPort;
if (aboutWindow && aboutGW)
{
if (evt->modifiers & alphaLock)
ticksBetweenUpdate = 0xFFFFFFFF;
else
{
if (evt->modifiers & cmdKey)
ticksBetweenUpdate >>= 2; // cmd key = 4x as fast
else if (evt->modifiers & optionKey)
ticksBetweenUpdate >>= 1; // option key = 2x as fast
}
if (TickCount() - lastTick >= ticksBetweenUpdate)
{
GetPort(&oldPort);
SetPort(aboutWindow);
LockPixels(GetGWorldPixMap(aboutGW));
r = targR;
r.left += adder;
r.right += adder;
// first time, draw in new location, then unoffset the rectangle and erase the old
CopyBits(&((GrafPtr)aboutGW)->portBits, &aboutWindow->portBits, &srcR, &r,
srcCopy, nil);
if (r.right < aboutR.right)
{
OffsetRect(&r, r.right - r.left, 0);
CopyBits(&((GrafPtr)aboutGW)->portBits, &aboutWindow->portBits, &srcR, &r,
srcCopy, nil);
}
UnlockPixels(GetGWorldPixMap(aboutGW));
targR.left += adder;
targR.right += adder;
if (targR.right < 0)
OffsetRect(&targR, targR.right - targR.left, 0);
SetPort(oldPort);
lastTick = TickCount();
}
}
RestoreA4World(oldA4);
return(retVal);
}
void StartAnimation(void)
{
GrafPtr oldPort;
OSErr err;
CGrafPtr oldGW;
GDHandle oldGD;
if (!aboutGW)
{
short wid = 0;
short nextChar;
Style currStyle = 0;
short txFont;
short txSize;
Style txFace;
GetPort(&oldPort);
SetPort(aboutWindow);
txFont = aboutWindow->txFont;
txSize = aboutWindow->txSize;
txFace = aboutWindow->txFace;
TextFont(geneva);
TextSize(9);
TextFace(currStyle);
for (nextChar = 1; nextChar <= aboutStr[0]; ++nextChar)
{
if (aboutStr[nextChar] == '%')
{
switch (aboutStr[++nextChar])
{
case 'P':
currStyle = 0;
break;
case 'B':
currStyle ^= bold;
break;
case 'I':
currStyle ^= italic;
break;
case 'C':
currStyle ^= condense;
break;
}
TextFace(currStyle);
}
else
wid += CharWidth(aboutStr[nextChar]);
}
aboutWindow->txFont = txFont;
aboutWindow->txSize = txSize;
aboutWindow->txFace = txFace;
SetPort(oldPort);
// now, create a GWorld that is wid pixels wide and 13 pixels tall
GetGWorld(&oldGW, &oldGD);
srcR.left = 0;
srcR.top = 0;
srcR.bottom = 12;
srcR.right = wid;
err = NewGWorld(&aboutGW, 1, &srcR, nil, nil, useTempMem);
if (!err && aboutGW)
{
LockPixels(GetGWorldPixMap(aboutGW));
SetGWorld(aboutGW, nil);
EraseRect(&srcR);
currStyle = 0;
TextFont(geneva);
TextSize(9);
TextFace(currStyle);
// draw the string into the GWorld
MoveTo(0, 9);
for (nextChar = 1; nextChar <= aboutStr[0]; ++nextChar)
{
if (aboutStr[nextChar] == '%')
{
switch (aboutStr[++nextChar])
{
case 'P':
currStyle = 0;
break;
case 'B':
currStyle ^= bold;
break;
case 'I':
currStyle ^= italic;
break;
case 'C':
currStyle ^= condense;
break;
}
TextFace(currStyle);
}
else
DrawChar(aboutStr[nextChar]);
}
SetGWorld(oldGW, oldGD);
UnlockPixels(GetGWorldPixMap(aboutGW));
}
}
targR = srcR;
OffsetRect(&targR, aboutR.right, aboutR.top);
lastTick = 0;
if (!oldGetNextEvent)
{
oldGetNextEvent = (void*) GetToolTrapAddress(_GetNextEvent);
SetToolTrapAddress((void*) MyGetNextEvent, _GetNextEvent);
}
}
void StopAnimation(void)
{
GrafPtr oldPort;
if (oldGetNextEvent)
SetToolTrapAddress((void*) oldGetNextEvent, _GetNextEvent);
oldGetNextEvent = nil;
//if (aboutGW)
// DisposeGWorld(aboutGW);
//aboutGW = nil;
}